package com.demo.myapplication.mvp.presenter;

import com.demo.myapplication.mvp.model.User;
import com.demo.myapplication.mvp.model.UserInteractor;
import com.demo.myapplication.mvp.view.UserView;

public class UserPresenter implements BasePresenter {
  private UserView mUserView;
  private UserInteractor messageInterface;

  public UserPresenter(UserView mUserView, UserInteractor messageInterface) {
    this.mUserView = mUserView;
    this.messageInterface = messageInterface;
  }

  public void loadLoginUserAndPwd() {
    User user = messageInterface.getUser();
    String name = user.getUsername();
    String pwd = user.getPassword();
    this.mUserView.showUserAndPwd(name, pwd);
  }


  public void login(String username, String pwd) {
    User user = messageInterface.getUser();
    if (username.equals(user.getUsername()) && pwd.equals(user.getPassword())) {
      this.mUserView.showLoginResult("login success");
    } else {
      this.mUserView.showLoginResult("login fail");
    }
  }

  @Override
  public void start() {

  }

  @Override
  public void resume() {
    loadLoginUserAndPwd();
  }

  @Override
  public void pause() {

  }

  @Override
  public void stop() {

  }

  @Override
  public void destroy() {
    this.mUserView = null;
  }
}
